﻿package com.designoutput.ui.controls
{
    import com.designoutput.icon.ButtonFillOff;
    import com.designoutput.icon.ButtonFillOn;
    
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;

    public class Button extends Sprite
    {
        internal var over:Bitmap;
        internal var bg:Sprite;
        public var title:TextField;
        internal var out:Bitmap;

        public function Button(label:String, width:int)
        {
            this.graphics.beginFill(9474192);
            this.graphics.drawRect(0, 0, width, 20);
            this.graphics.beginFill(16777215);
            this.graphics.drawRect(1, 1, width - 2, 18);
            this.graphics.endFill();
            this.addEventListener(MouseEvent.MOUSE_OVER, this.MouseOver, false, 0, true);
            this.addEventListener(MouseEvent.MOUSE_OUT, this.MouseOut, false, 0, true);
            this.out = new Bitmap(new ButtonFillOff(0, 0));
            this.over = new Bitmap(new ButtonFillOn(0, 0));
            this.out.x = this.out.y = this.over.x =this.over.y = 2;
            this.out.width =this.over.width = width - 4;
            addChild(this.out);
            this.title = new TextField();
            this.title.y = 1;
            this.title.defaultTextFormat = new TextFormat("Arial, Helvetica, San-serif", 12, 0, false, false, false, null, null, "center");
            this.title.height = 18;
            this.title.multiline = false;
            this.title.selectable = false;
            this.title.width = width;
            this.title.text = label;
            addChild(this.title);
        }

        private function MouseOut(event:MouseEvent) : void
        {
            this.removeChildAt(0);
            this.addChildAt(this.out, 0);
        }

        private function MouseOver(event:MouseEvent) : void
        {
            this.removeChildAt(0);
            this.addChildAt(this.over, 0);
        }
		
		public function set Label(val:String):void{
			this.title.text = val;
		}

    }
}
